<?php
	$root = "http://".$_SERVER['HTTP_HOST']."/".substr($_SERVER['PHP_SELF'], 1, strpos(substr($_SERVER['PHP_SELF'], 1), "/"))."/";
?>
<!DOCTYPE html>
<!-- 
文件用途:登录页面
作者:hjl
制作日期:2012-11-27
最后编辑人:hjl
最后编辑时间:2012-11-27
-->
<html lang="en" class="login_page">
  <head>
    <base href="<?php echo $root;?>">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0"> 
	<title>系统登录</title>
    <?php include '../pages/common/importBaseCss.php'; ?> 
  </head>  
  <body>
		<div class="login_box">
			<form id="login_form">
				<div class="top_b">登录-矿井信息化综合管理平台</div>    
				<div class="alert alert-info alert-login">
					请键入工号,密码,验证码.
				</div>
				<div class="cnt_b">
					<div class="formRow">
						<div class="input-prepend">
							<span class="add-on"><i class="icon-user"></i></span><input type="text" id="workno" name="workno" placeholder="工号"/>
						</div>
					</div>
					<div class="formRow">
						<div class="input-prepend">
							<span class="add-on"><i class="icon-lock"></i></span><input type="password" id="password" name="password" placeholder="密码"/>
						</div>
					</div>
					<div class="formRow">
						<div class="input-prepend">
							<span class="add-on"><img src="img/verifycodeDemo.bmp" width="60px" heigth="20px"></img></span><input type="text" id="verifycode" name="verifycode" placeholder="验证码" class="span2"/>
						</div>
					</div>
					<div class="formRow clearfix">
						<label class="checkbox"><input type="checkbox" />记住我</label>
					</div>
				</div>
				<div class="btm_b clearfix">
					<button class="btn btn-inverse pull-right" type="submit">登录</button>
				</div>  
			</form>
		</div>
  </body>
  <?php include '../pages/common/importBaseJs.php'; ?>
        <script>
    	/*
    	*文件用途:列表综合模板展示
    	*作者:hjl
    	*制作日期:2012-11-22
    	*最后编辑人:hjl
    	*最后编辑时间:2012-11-23
    	*/	
    	//================
    	//模块入口
    	//================
        $(document).ready(function() {
            app.regLogin();
        });        
        app = {
        	regLogin: function(){
				//* boxes animation
				var form_wrapper = $('.login_box');
				form_wrapper.css({ marginTop : ( - ( form_wrapper.height() / 2) - 24) });
				var postForm = $('#login_form'); 				
				//* validation
				postForm.validate({
					onkeyup: false,
					errorClass: 'error',
					validClass: 'valid',
					rules: {
						workno: { required: true, minlength: 3 },
						password: { required: true, minlength: 3 },
						verifycode: { required: true }
					},
					submitHandler : function(form){
						app.login(postForm);
					},
					highlight: function(element) {
						$(element).closest('div').addClass("f_error");
						setTimeout(function() {
							form_wrapper.animate({ marginTop : ( - ( form_wrapper.height() / 2) - 24) },400);
						}, 200)
					},
					unhighlight: function(element) {
						$(element).closest('div').removeClass("f_error");
						setTimeout(function() {
							form_wrapper.animate({ marginTop : ( - ( form_wrapper.height() / 2) - 24) },400);
						}, 200)
					},
					errorPlacement: function(error, element) {
						$(element).closest('div').append(error);
					}
				});
        	},
        	login: function(form){
               	var postData = form.formSerialize();
            	$.ajax({
                        type : "post",
                        url : "listbox/login.nut",
                        data : postData,
                        dataType : "json",
                        beforeSend : function(XMLHttpRequest){
                            form.find("input[type='submit']").addClass("disabled").removeClass("btn-inverse").val("处理中...");
                        },
                        success : function(msg,textStatus){
    						form.find("input[type='submit']").removeClass("disabled").addClass("btn-inverse").val("登录");
    						if(msg.state=="success"){
    							window.location.href = "index.jsp";
                			}else
                    		if(msg.state=="fail"){
                    			$(".alert-login").removeClass("alert-info").addClass("alert-error").text("登录失败!工号或密码错误");
                        	}	
                        },
                        error : function(XMLHttpRequest, textStatus, errorThrown){
                        	$(".alert-login").removeClass("alert-info").addClass("alert-error").text("服务器出错,请稍候再试!");
                        },
                        complete : function(XMLHttpRequest, textStatus){
                            form.clearForm();
                         	form.find("div").removeClass("f_success");   
                        }
             	}); 
 
            }     
        }
        </script>
</html>
